home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / gcc / ixemul41.lha / ixemul-41.3 / gnulib-soft-float / ldexp.c < prev    next >
C/C++ Source or Header  |  1994-08-19  |  1KB  |  57 lines

  1. /*
  2.  * ldexp returns the quanity "value" * 2 ^ "exp"
  3.  *
  4.  * For the mc68000 using IEEE format the double precision word format is:
  5.  *
  6.  * WORD N   =>    SEEEEEEEEEEEMMMM
  7.  * WORD N+1 =>    MMMMMMMMMMMMMMMM
  8.  * WORD N+2 =>    MMMMMMMMMMMMMMMM
  9.  * WORD N+3 =>    MMMMMMMMMMMMMMMM
  10.  *
  11.  * Where:          S  =>   Sign bit
  12.  *                 E  =>   Exponent
  13.  *                 X  =>   Ignored (set to 0)
  14.  *                 M  =>   Mantissa bit
  15.  *
  16.  * NOTE:  Beware of 0.0; on some machines which use excess 128 notation for the
  17.  * exponent, if the mantissa is zero the exponent is also.
  18.  *
  19.  */
  20.  
  21. #define MANT_MASK 0x800FFFFF    /* Mantissa extraction mask     */
  22. #define ZPOS_MASK 0x3FF00000    /* Positive # mask for exp = 0  */
  23. #define ZNEG_MASK 0x3FF00000    /* Negative # mask for exp = 0  */
  24.  
  25. #define EXP_MASK 0x7FF00000    /* Mask for exponent            */
  26. #define EXP_SHIFTS 20        /* Shifts to get into LSB's     */
  27. #define EXP_BIAS 1023        /* Exponent bias                */
  28.  
  29.  
  30. union dtol
  31. {
  32.   double dval;
  33.   int ival[2];
  34. };
  35.  
  36. double
  37. ldexp (value, exp)
  38.      double value;
  39.      int exp;
  40. {
  41.   union dtol number;
  42.   int *iptr, cexp;
  43.  
  44.   if (value == 0.0)
  45.     return (0.0);
  46.   else
  47.     {
  48.       number.dval = value;
  49.       iptr = &number.ival[0];
  50.       cexp = (((*iptr) & EXP_MASK) >> EXP_SHIFTS) - EXP_BIAS;
  51.       *iptr &= ~EXP_MASK;
  52.       exp += EXP_BIAS;
  53.       *iptr |= ((exp + cexp) << EXP_SHIFTS) & EXP_MASK;
  54.       return (number.dval);
  55.     }
  56. }
  57.